package com.example.bookmanagersystem.repository;

import com.example.bookmanagersystem.entity.Book;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BookRepository extends JpaRepository<Book, Long> {
    // 根据书名查询
    List<Book> findByTitleContaining(String title);

    // 根据作者查询
    List<Book> findByAuthorContaining(String author);

    // 根据ISBN查询
    Book findByIsbn(String isbn);

    // 查找有库存的书籍
    @Query("SELECT b FROM Book b WHERE b.stock > 0")
    List<Book> findAvailableBooks();
}